package com.adam.management.excel;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;

public class MyCallable implements Callable<List<Map<String,Object>>> {

   private int sheetIndex;

   private MultipartFile file;

   private CountDownLatch count;

   private List<Map<String,Object>> readAll;


    public MyCallable(int sheetIndex, MultipartFile file, CountDownLatch count){
        this.sheetIndex = sheetIndex;
        this.file = file;
        this.count = count;
    }

    @Override
    public List<Map<String,Object>> call() throws Exception {
        InputStream inputStream = file.getInputStream();
        ExcelReader reader = ExcelUtil.getReader(inputStream, sheetIndex);
        //读取为Map列表，默认第一行为标题行，Map中的key为标题，value为标题对应的单元格值。
        readAll = reader.readAll();
        System.out.println(Thread.currentThread().getName()+":"+readAll.toString());
        System.out.println("线程"+sheetIndex);
        count.countDown();
        return readAll;
    }
}
